﻿import groovy.text.SimpleTemplateEngine

class BaseControllerBase {
    File getSqlTemplateFile(String fileName) {
        if (!fileName.endsWith(".gtpl"))
            fileName = fileName + ".gtpl";
        def ctx = grailsAttributes.getApplicationContext();
        def resourceLoader = ctx.containsBean('groovyPageResourceLoader') ? ctx.groovyPageResourceLoader : ctx;
        File gtpl = resourceLoader.getResource(File.separator + "templates" + File.separator + "sql" + File.separator + fileName).getFile();
    }
    Object getActiveOffersNum(String realtyType, SqlService sqlService){
        File file = getSqlTemplateFile("activeOffersNum");
        def engine = new SimpleTemplateEngine();
        def binding = ["realtyType":realtyType];
        def template = engine.createTemplate(file).make(binding);
        def offersNum = (ArrayList) sqlService.executeQueryMap(template.toString());
        Map map =  (Map)offersNum.get(0);

        return map.get("num");

    }
}